package com.baosight.risk.common.sso;

import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.security.base.SecurityFactory;
import com.baosight.iplat4j.core.security.sso.SSOCredential;
import com.baosight.iplat4j.core.security.user.IUserManager;
import com.baosight.iplat4j.core.security.user.User;
import com.baosight.iplat4j.core.service.soa.XServiceManager;
import com.baosight.risk.common.utils.ShiroUtils;
import com.baosight.risk.service.xtzy.entity.XtzyUser;
import com.baosight.xservices.xs.ISecurityUser;
import com.baosight.xservices.xs.impl.SecurityUserStandardImpl;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Calendar;

/**
 * @Author phinxe
 * @Date 2019-07-08
 */
public class TokenSso implements SSOCredential {
    @Autowired
    private ISecurityUser securityUser;

    @Override
    //cre对应p_password参数，user对应p_username参数，根据验证算法返回结果
    public boolean validateCredential(String cre, String user) {
        EiInfo eiInfo = new EiInfo();
        eiInfo.set(EiConstant.serviceId, "S_XS_03");
        eiInfo.set("loginName", user);
        eiInfo.set("password", cre);
//        eiInfo.set(EiConstant.serviceName, "getUser");
//        EiInfo outInfo = XServiceManager.call(eiInfo);
        EiInfo userInfo = securityUser.validateUser(eiInfo);
        if (userInfo.getStatus() == 1) {
            return true;
        }
//        if (outInfo.getStatus() == 1) {
//            return true;
//        }
        return false;
    }

    @Override
    public String composeCredential(String user, String target) {
        return null;
    }
}
